package com.songxu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.songxu.util.SecurityUtil;
import com.songxu.util.WebUtil;

import net.sf.json.JSON;
import net.sf.json.JSONObject;

/**
 * Servlet implementation class SecurityCheck
 */
@WebServlet("/SecurityCheck")
public class SecurityCheck extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SecurityCheck() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String host=request.getRemoteAddr();
		String urlString=WebUtil.getDomain(request)+"manager/html";
		
		JSONObject obJson=new JSONObject();
		if(SecurityUtil.permit(request.getServletContext(), host))
		{
			obJson.put("status", true);
			obJson.put("url", urlString);
		}
		else {
			obJson.put("status", false);
			obJson.put("url", "");
		}
		
		response.getWriter().write(obJson.toString());
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
